
#pragma once

static void prn( const char * obj_name, Obj * obj )
{
    fprintf( stderr, "%s = ", obj_name );
    print_obj( obj, stderr );
    fputs( ".\n", stderr );
}

static void test_listv( AllocContext * ac )
{
    List *    l = alloc_listv( ac, g_t_obj, alloc_id(ac, "asdf", 0), alloc_int_num(ac, 45), 0 );
    
    prn( "listv", (Obj *)l );
}

static void test_listn( AllocContext * ac )
{
    Obj *       arr[3];
    List *      l;

    arr[0] = (Obj *)alloc_dbl_num( ac, 3.14 );
    arr[1] = g_nil_obj;
    arr[2] = (Obj *)alloc_listv( ac, g_t_obj, alloc_id(ac, "ident", 0), 0 );

    l = alloc_listn( ac, arr, 3 );
    
    prn( "listn", (Obj *)l );
}

static void test_list_manip( AllocContext * ac )
{
    Id *        id = alloc_id( ac, "boo", 0 );
    List *      l = alloc_list( ac );
    List *      l2 = alloc_listv( ac, g_t_obj, alloc_id(ac, "ident", 0), alloc_dbl_num(ac, 3.14), g_nil_obj, 0 );
    IntNum *    n = alloc_int_num( ac, 54 );
    Obj *       r;

    test_listn( ac );
    test_listv( ac );

    list_push( ac, l, (Obj *)id );
    list_push( ac, l, g_t_obj );
    list_push( ac, l, (Obj *)n );
    list_add( ac, l, (Obj *)alloc_int_num(ac, 1983) );

    prn( "l", (Obj *)l );

    fprintf( stderr, "length( l ) = %d\n", list_length(l) );
    
    list_set_at( l, 1, g_nil_obj );
    prn( "after set l", (Obj *)l );

    while( r = list_pop(ac, l) )
    {
        prn( "r", r );
    }

    l = alloc_listv( ac, (Obj *)alloc_id(ac, "gogo", 0), alloc_int_num(ac, 7756), 0 );
    list_append( l, l2 );
    prn( "l + l2 = ", (Obj *)l );
}
